<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
</head>

<body>
    <div id="app">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">用户: {{username}} 我的租用</h3>
            </div>
            <div class="panel-body form-inline">
                <a href="user_main.html"><button class="btn btn-primary">返回主页面</button></a>
                <a href="user_buy.html"><button class="btn btn-primary">查看我的购买</button></a>
            </div>
        </div>

        <table class="table table-bordered table-hover table-striped">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>名称</th>
                    <th>价格</th>
                    <th>租借数量</th>
                    <th>租借天数</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in list" :key="item.id">
                    <td> {{item.id}} </td>
                    <td> {{item.goodname}} </td>
                    <td> {{item.goodprice}}元/天 </td>
                    <td> {{item.number}} </td>
                    <td> {{item.day}}天 </td>
                </tr>
            </tbody>
            <span> 共 {{list.length}} 个商品 </span>
        </table>
    </div>
</body>
<script src="js/vue.js"></script>
<script src="js/vue-resource.min.js"></script>
<script>
    Vue.http.options.emulateJSON = true;
    var vm = new Vue({
        el: "#app",
        data: {
            username: '',
            list: []
        },
        methods: {
            getMes: function () {
                this.username = JSON.parse(localStorage.getItem('name'));
            },
            getAllList: function () {
                this.$http.post('php/user_rent.php', {
                    username: this.username
                }, {
                    emulateJSON: true
                }).then(function (result) {
                    this.list = result.body;
                })
            }
        },
        created() {
            this.getMes();
            this.getAllList();
        }
    })
</script>

</html>